package com.hexacta.hrs.sandbox.pr.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.hexacta.hrs.sandbox.pr.data.Dao;
import com.hexacta.hrs.sandbox.pr.model.Category;
import com.hexacta.hrs.sandbox.pr.model.Review;

public class ReviewServiceImpl implements ReviewService {
	
	@Autowired
	private Dao dao;

	public Dao getDao() {
		return dao;
	}

	public void setDao(Dao dao) {
		this.dao = dao;
	}
	
	public Long addReview(Review review) {
		return this.getDao().add(review);
	}

	@SuppressWarnings("unchecked")
	public List<Review> listAll() {
		return (List<Review>) this.getDao().listAll(Review.class);
	}

	public void removeReview(Review review) {
		this.getDao().remove(review);
	}

	@Override
	public Long addReview(Date date, Category category,
			Integer recommendedRevisorsQ) {
		
		Review review = new Review();
		review.setDate(date);
		review.setCategory(category);
		review.setRecommendedRevisorsQ(recommendedRevisorsQ);
		return this.addReview(review);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Review> findReviewById(Long id) {
		return (List<Review>) this.getDao().findById(Review.class, id);		
	}

	@Override
	public void update(Review review) {
		this.getDao().update(review);
	}
}